package com.example.bes10.springboot2.bcs.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/bcs")
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping(value = "/add/{key}/{value}")
    public void addKey(@PathVariable(value = "key") String key, @PathVariable(value = "value") String value) {
        redisTemplate.opsForValue().set(key, value);
    }

    @GetMapping(value = "/get/{key}")
    public String getKey(@PathVariable(value = "key") String key) {
        return String.valueOf(redisTemplate.opsForValue().get(key));
    }

    @GetMapping(value = "/del/{key}")
    public boolean deleteKey(@PathVariable(value = "key") String key) {
        return redisTemplate.delete(key);
    }

}
